package com.itheima.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.stereotype.Component;

//阿里大于发送短信dome
@Component
public class SendSmsUtils{

    public static void sendSms(String telephone,String message) {

        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5tFJgni2eo7AMi24QuQr", "Imu0eJImVSKKbVanOlJuxnCLF0X93i");

        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("PhoneNumbers", telephone);
        request.putQueryParameter("SignName", "绾珏");
        request.putQueryParameter("TemplateCode", "SMS_181540005");
        request.putQueryParameter("TemplateParam", message);

        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}